package spring.jdbc;

import java.util.Map;

import javax.sql.DataSource;

import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcCall;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;

import spring.bean.Person;

public class JdbcOtherDaoImpl implements JdbcOtherDao{
	private DataSource dataSource;
	private SimpleJdbcTemplate simpleJdbcTemplate;
	private SimpleJdbcCall simpleJdbcCall;
	
	public void init(){
		simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
		simpleJdbcCall = new SimpleJdbcCall(dataSource).withProcedureName("readPerson");
	}
	
	public void readPerson(long id){
		SqlParameterSource source=new MapSqlParameterSource().addValue("in_id", id);
		Map<String, Object> out=simpleJdbcCall.execute(source);
		Person person=new Person();
		person.setName((String)out.get("name"));
		person.setBirthday((String)out.get("birthday"));
		person.setDes((String)out.get("des"));
		System.out.println(person);
	}
	
	
	public DataSource getDataSource() {
		return dataSource;
	}
	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}
}



